using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CentralOffice.Enterprise.Data;
using CentralOffice.Enterprise.BusinessActions;
using NoticeTable = CentralOffice.Enterprise.Data.EnterpriseNoticeDataSet.NoticesDataTable;
using NoticeRow = CentralOffice.Enterprise.Data.EnterpriseNoticeDataSet.NoticesRow;
using ReceiverTable = CentralOffice.Enterprise.Data.NoticeReceiverDataSet.NoticeReceiverDataTable;
using ReceiverRow = CentralOffice.Enterprise.Data.NoticeReceiverDataSet.NoticeReceiverRow;

namespace CentralOffice.WebClient.Enterprises
{
    public partial class NoticeToMy : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //SiteUtil.PopulateListBox(ddlSignificant, SiteConstants.Significant, false);
                SiteUtil.PopulateListBox(ddlSignificant, SiteConstants.Significant, true);
                if (ddlSignificant.Items.Count > 1)
                {
                    ddlSignificant.SelectedIndex = 1;
                }
                else
                {
                    ddlSignificant.SelectedIndex = 0;
                }
            }
        }

        //protected void odsNotice_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        //{
        //}

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            gvMyNotice.PageIndex = 0;

            ReceiverRow row = (new NoticeReceiverDataSet()).NoticeReceiver.NewNoticeReceiverRow();

            row.EnterpriseId = ApplicationContext.EnterpriseId;
            row.NoticeTitle = txtNoticeTitle.Text;
            if (txtPublishDate.Text.Length > 0)
            {
                row.PublishDate = DateTime.Parse(txtPublishDate.Text);
            }
            if (txtPublishDateEnd.Text.Length > 0)
            {
                row.PublishDateEnd = DateTime.Parse(txtPublishDateEnd.Text);
            }
            //row.Significant = ddlSignificant.SelectedItem.Text;
            if (ddlSignificant.SelectedIndex > 0)
            {
                row.Significant = ddlSignificant.SelectedItem.Text;
            }


            //if (ddlCategory.SelectIndex > 0 && ddlCategory.SelectId != null)
            //{
            //    task.CategoryId = ddlCategory.SelectId.Value;
            //}

            //task.Significant = ddlPriority.SelectedItem.Text;

            //task.Accepter = txtAccepter.Value;

            //if (txtIntendingDate.Text.Length > 0)
            //{
            //    task.IntendingDate = DateTime.Parse(txtIntendingDate.Text);
            //}
            //if (txtApprovedDate.Text.Length > 0)
            //{
            //    task.ApprovedDate = DateTime.Parse(txtApprovedDate.Text);
            //}
            ////task.CloseDate = txtCloseDate.Text;
            ////task.Profile = txtProfile.Text;

            //e.InputParameters["whereClause"] = row.EnterpriseId == Guid.Empty ? " 0 = 1 " : row.FilterExpression;
            odsMyNotice.SelectParameters["whereClause"].DefaultValue = row.EnterpriseId == Guid.Empty ? " 0 = 1 " : row.FilterExpression;
        }

        protected void odsMyNotice_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (!e.ExecutingSelectCount)
            {
                //e.Arguments
            }
            if (this.IsPostBack)
            {
                ReceiverRow row = (new NoticeReceiverDataSet()).NoticeReceiver.NewNoticeReceiverRow();

                row.EnterpriseId = ApplicationContext.EnterpriseId;
                row.NoticeTitle = txtNoticeTitle.Text;
                if (txtPublishDate.Text.Length > 0)
                {
                    row.PublishDate = DateTime.Parse(txtPublishDate.Text);
                }
                if (txtPublishDateEnd.Text.Length > 0)
                {
                    row.PublishDateEnd = DateTime.Parse(txtPublishDateEnd.Text);
                }
                row.Significant = ddlSignificant.SelectedItem.Text;


                //if (ddlCategory.SelectIndex > 0 && ddlCategory.SelectId != null)
                //{
                //    task.CategoryId = ddlCategory.SelectId.Value;
                //}

                //task.Significant = ddlPriority.SelectedItem.Text;

                //task.Accepter = txtAccepter.Value;

                //if (txtIntendingDate.Text.Length > 0)
                //{
                //    task.IntendingDate = DateTime.Parse(txtIntendingDate.Text);
                //}
                //if (txtApprovedDate.Text.Length > 0)
                //{
                //    task.ApprovedDate = DateTime.Parse(txtApprovedDate.Text);
                //}
                ////task.CloseDate = txtCloseDate.Text;
                ////task.Profile = txtProfile.Text;

                e.InputParameters["whereClause"] = row.EnterpriseId == Guid.Empty ? " 0 = 1 " : row.FilterExpression;

                //odsTask.SelectParameters["whereClause"] = task.FilterExpression;//companyInfo.FilterExpression
            }
            else
            {
                e.InputParameters["whereClause"] = "EnterpriseId = '" + ApplicationContext.EnterpriseId + "'";
            }
        }
    }
}
